import { _decorator, AssetManager, assetManager, Component, JsonAsset, Node } from 'cc';
import { GameSDK } from '../bundles/sdk/GameSDK';
import { ConfigManager, LoaderBundle, LoaderManager, Logger, UILayerIndex, UIManager } from '../bundles/sdk/API';
import { TestEntity } from '../bundles/hall/src/test/TestEntity';
import { ObjectPool } from '../bundles/frame/manager/ObjectPool';
const { ccclass, property } = _decorator; 
 
@ccclass('StartUp')
export class StartUp extends Component { 
    @property sdk_config_url:string="http://192.168.0.31/sdk/sdkConfig.json"
    protected __preload(){ 
        assetManager.loadRemote(`${this.sdk_config_url}?time=${Date.now()}`,(err: Error | null, data: JsonAsset)=>{
            if(!err){
                console.warn("SDK config loading complete")
                GameSDK.getInstance().initGameSDK(data.json.url,data.json.version,data.json.path,this.onSDKComplete.bind(this))
            }else{
                console.error("SDK config loading error")
            }
        })
    } 
    start() {
        let test:any={name:"sword"} 

        let ss = ObjectPool.getObj(test) 
        console.log("----")
        
    }

    private onSDKComplete(){
        Logger.log("--onSDKComplete---")
        ConfigManager.getInstance().debug=false
        LoaderManager.getInstance().loadBundle("bundles/hall",null,null,async (loader:LoaderBundle)=>{
            await ConfigManager.getInstance().loadBundle("bundles/config")
            //let c:gameConfig=ConfigManager.getInstance().getConfig(null,"game",{id:1000,price:50},gameConfig)
            UIManager.getInstance().show(loader.path,"res/prefab/test",2,TestEntity)

        })
       
    } 
}